package com.socialuni.center.web.factory;

import com.socialuni.sdk.api.model.RO.comment.TalkCommentRO;
import com.socialuni.sdk.api.model.RO.talk.SocialTalkImgRO;
import com.socialuni.sdk.api.model.RO.talk.SocialTalkRO;
import com.socialuni.sdk.api.model.RO.user.SocialTalkUserRO;
import com.socialuni.center.web.utils.UnionIdDbUtil;
import com.socialuni.sdk.factory.ListConvertUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 不需要像帖子一样，每次有回复都刷新，因为不愁看，且你评论后的，有动静你会有通知
 */
@Data
@Component
@Slf4j
public class CenterTalkROFactory {
    //需要user因为，user需要外部传入，区分center和social
    //用户详情
    public static SocialTalkRO newHomeTalkRO(SocialTalkRO talkRO) {
        String talkId = UnionIdDbUtil.createTalkUid(talkRO.getId());

//        private SocialTalkUserRO user;
        SocialTalkUserRO socialTalkUserRO = CenterTalkUserROFactory.newHomeTalkUserRO(talkRO.getUser());
        List<SocialTalkImgRO> imgs = CenterTalkImgROFactory.newHomeTalkImgROS(talkRO.getImgs());

        List<TalkCommentRO> comments = CenterCommentROFactory.newHomeCommentROS(talkRO.getComments());

        talkRO.setId(talkId);
        talkRO.setUser(socialTalkUserRO);
        talkRO.setImgs(imgs);
        talkRO.setComments(comments);
        return talkRO;
    }

    public static List<SocialTalkRO> newHomeCommentROS(List<SocialTalkRO> ROS) {
        return ListConvertUtil.toList(ROS, CenterTalkROFactory::newHomeTalkRO);
    }
}